
export default {
  actionName:'',
  editColumns:[],
  editRule:{},
  tableColumns:[],
  data(){
    return {
      tableOptions:{
        pageNum: 1,
        pageSize: 10,
        orderByColumn:"id",
        isAsc: "desc",
        total:0,
        loading:false,
        data:[]
      },
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true
    }
  },
  methods:{
    /** 查询列表 */
    getList() {
      let pm = this.$refs.search.getData();
      pm = Object.assign(_.pick(this.tableOptions,['pageNum','pageSize']),pm);
      this.api(`${this.actionName}.list`,pm,this.tableOptions).then((response)=>{
        this.tableOptions.data = response.rows;
        this.tableOptions.total = response.total;
        this.$forceUpdate();
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.tableOptions.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.$refs.search.resetForm();
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.dialogEdit({
        PATH_SAVE:`${this.actionName}.add`,
        width:"90%",
        size:6,
        labelWidth:"9em",
        columns:this.editColumns,
        rules:this.editRule
      },()=>{
        this.getList();
      })
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.dialogEdit({
        row,
        PATH_SAVE:`${this.actionName}.edit`,
        width:"90%",
        size:6,
        labelWidth:"9em",
        columns:this.editColumns,
        rules:this.editRule
      },()=>{
        this.getList();
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm(`是否确认删除【${row.id}】的数据项？`).then(()=>{
        return this.api(`${this.actionName}.del`,ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      let pm = this.$refs.search.getData();
      this.download(`basic/${this.actionName}/export`, {...pm}, `administration_${new Date().getTime()}.xlsx`)
    },
    /** 跳转 */
    go(url,key = {id:"id"}){
      return (row)=>{
        let query = {};
        Object.keys(key).map((v)=>{
          query[v] = row[key[v]];
        })
        //
        this.$router.push({
          path:url,
          query:query
        })
      }
    }
  }
}
